<template>
  <div class="row">
    <div v-for="column in columnList" :key="column.id" class="col-4">
      <div class="card">
        <div class="card-body text-center">
          <img :src="column.avatar" class="card-img-top rounded-circle border border-light w-25 my-3" :alt="column.description">
          <h5 class="card-title">{{column.title}}</h5>
          <p class="card-text text-left">{{column.description}}</p>
          <a href="#" class="btn btn-outline-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'
import 'bootstrap/dist/css/bootstrap.min.css'
export interface ColumnProps {
  id: number
  title: string
  description: string
  avatar: string
}
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(column => {
        if (!column.avatar) {
          column.avatar = require('@/assets/column.jpg')
        }
        return column
      })
    })
    return {
      columnList
    }
  }
})
</script>

<style>

</style>
